package com.rm.zeyou.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rm.zeyou.entity.Technician;
import com.rm.zeyou.entity.TechnicianAppraise;
import com.rm.zeyou.mapper.TechnicianAppraiseMapper;
import com.rm.zeyou.mapper.TechnicianMapper;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.TechnicianAppraiseService;
import com.rm.zeyou.util.check.CheckEmptyUtil;
import com.rm.zeyou.vo.request.TechnicianAppraiseListVo;
import com.rm.zeyou.vo.response.TechnicianAppraiseListResponseVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 技师评价表 服务实现类
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Service
public class TechnicianAppraiseServiceImpl extends ServiceImpl<TechnicianAppraiseMapper, TechnicianAppraise> implements TechnicianAppraiseService {
    @Resource
    private TechnicianAppraiseMapper technicianAppraiseMapper;
    @Resource
    private TechnicianMapper technicianMapper;

    @Override
    public ApiRestResponse<PageInfo<TechnicianAppraiseListResponseVo>> technicianAppraiseList(Technician technician, TechnicianAppraiseListVo requestVo) {
        PageHelper.startPage(requestVo.getPageNum(), requestVo.getPageSize());
        List<TechnicianAppraise> responseVoList = technicianAppraiseMapper.technicianAppraiseList(requestVo.getUserId());
        List<TechnicianAppraiseListResponseVo> responseVoListResponseVo = new ArrayList<>();
        if (!CheckEmptyUtil.isEmpty(responseVoList)) {
            PageInfo<TechnicianAppraise> source = new PageInfo<>(responseVoList);
            PageInfo<TechnicianAppraiseListResponseVo> target = new PageInfo<>();
            BeanUtils.copyProperties(source, target);

            source.getList().forEach(item -> {
                TechnicianAppraiseListResponseVo vo = new TechnicianAppraiseListResponseVo();
                BeanUtils.copyProperties(item, vo);

                Technician technician1 = technicianMapper.selectById(item.getTechnicianId());
                vo.setTechnicianAvatar(technician1.getTechnicianAvatar());
                vo.setTechnicianName(technician1.getTechnicianName());
                responseVoListResponseVo.add(vo);
            });
            target.setList(responseVoListResponseVo);
            return ApiRestResponse.success(target);
        }


        return ApiRestResponse.success(new PageInfo<>());
    }
}
